package Array;

public class item1109 {
    public int[] corpFlightBookings(int[][] bookings, int n) {
      int[] diff = new int [n];
      int [] res = new int[n];
      for(int [] book :bookings)
      {
          int i = book[0]-1;
          int j = book[1] -1;
          int val = book[2];
          increament(res,diff,i,j,val);
      }
        return res;
    }

    private void increament(int[] res, int[] diff, int i, int j, int val) {
        diff[i]=val+diff[i];
        if(j+1<diff.length)
        {
            diff[j+1] = diff[j+1]-val;
        }
        res[0] = diff[0];
        for (int k = 1; k <diff.length ; k++) {
            res[i] = res[i-1]+diff[i];
        }

    }
}
